import {
  Controller,
  Get,
  Post,
  UseGuards,
  Body,
  Request,
  HttpCode,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { AuthService } from '../auth/auth.service';
import {
  ApiTags,
  ApiParam,
  ApiBody,
  ApiOperation,
  ApiResponse,
  ApiBearerAuth,
} from '@nestjs/swagger';
import { LocalAuthGuard } from '../auth/local-auth.guard';
import { LoginUserDto, CreateUserDto } from '../users/dto';

@Controller()
@ApiTags('登录-和注册接口')
export class LoginController {
  constructor(private authService: AuthService) {}

  //@UseGuards(LocalAuthGuard) //   不知道这是用来干嘛的，好像不用更好。
  @ApiOperation({ summary: '登录接口' })
  @Post('login')
  async login(@Body() loginUser: LoginUserDto) {
    return this.authService.validateUser(loginUser);
  }

  @Post('admin/login')
  async adminlogin(@Body() loginUser: LoginUserDto) {
    return this.authService.validateUserAdmin(loginUser);
  }

  @ApiOperation({ summary: '注册接口' })
  @Post('reg')
  reg(@Body() createUserDto: CreateUserDto) {
    return this.authService.reg(createUserDto);
  }

  @Get('init')
  init() {
    return this.authService.init();
  }
}
